package cn.tedu._05mvcboot01.controller;

import cn.tedu._05mvcboot01.pojo.dto.RegDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {
    @RequestMapping("/v1/users/login")
    @ResponseBody
    public String login(){
        return "恭喜你，登陆成功";
    }

//1、通过HttpServletRequest对象接收参数
    @RequestMapping("/v1/users/reg1")
    @ResponseBody
    public String reg1(HttpServletRequest request){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String nickname = request.getParameter("nickname");
        return username+":"+password+":"+nickname;
    }
    //2、通过声明参数的方式接收参数
    @RequestMapping("/v1/users/reg2")
    @ResponseBody
    public String reg2(String username,String password,String nickname){
        return username+":"+password+":"+nickname;
    }

    //3、DTO类的方式接收参数
    @RequestMapping("/v1/users/reg3")
    @ResponseBody
    public String reg3(RegDTO regDTO){
        String username = regDTO.getUsername();
        String password = regDTO.getPassword();
        String nickname = regDTO.getNickname();
        return username+":"+password+":"+nickname;
    }


}
